package org.rednebula.framework.core;

import java.io.Serializable;

import org.rednebula.framework.core.context.FlowContext;
import org.rednebula.framework.core.context.SpringContext;
import org.springframework.context.ApplicationContext;

public class SpringProcedurEngine extends ProcedureEngine implements
		Serializable {

	@Override
	public AbstractEnvironmentImpl getEnvironment() {
		AbstractEnvironmentImpl envi = AbstractEnvironmentImpl.getCurrent();
		try {
			if (envi == null) {
				envi = (AbstractEnvironmentImpl) this.getConfiguration()
						.getEnvironmentImpl();
				
				AbstractEnvironmentImpl.setEnvironment(envi);
				envi.setContext(this.getValueStackContext());
				envi.setContext(new FlowContext((ApplicationContext) this
						.getConfiguration().getApplicationContext()));
				envi.setEngine(this);
				envi.setContext(this.getServletContext());
				envi.setContext(this.getSessionContext());
				envi.setContext(this.getRequestContext());
				envi.setContext(new SpringContext((ApplicationContext) this
						.getConfiguration().getApplicationContext()));
			
			}
		} catch (Exception g) {

		}
		return envi;
	}

	public ApplicationContext getContext() {
		return (ApplicationContext) this.getConfiguration()
				.getApplicationContext();
	}
}
